package cn.stalk.wf.test;

import java.io.UnsupportedEncodingException;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

@Configuration
public class WebMvcHelper {

    @Bean
    public MockMvc setUp(WebApplicationContext context) {
        return MockMvcBuilders.webAppContextSetup(context).build();
    }

    public static String getResponseContentAsString(MvcResult result) throws UnsupportedEncodingException {
        MockHttpServletResponse response = result.getResponse();
        response.setCharacterEncoding("UTF-8");
        return response.getContentAsString();
    }
}
